package com.example.chapter0;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class TextViewActivity extends AppCompatActivity {
    @SuppressLint("ResourceAsColor")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_view);
        TextView textView = findViewById(R.id.tv_code_system);
        textView.setText(R.string.code_system);
        //设置系统自带颜色
        textView.setTextColor(Color.GREEN);
        LinearLayout layout = findViewById(R.id.ll_act_tv);
        TextView textView1 = new TextView(this);
        textView1.setText("设置透明颜色");
        textView1.setTextSize(30);
        textView1.setTextColor(0xff0000);
        layout.addView(textView1);
        TextView textView2 = new TextView(this);
        textView2.setText("代码实现文字");
        //设置八位颜色
        textView2.setTextColor(0xff0000ff);
        textView2.setTextSize(30);
        layout.addView(textView2);
        //引用资源颜色
        TextView textViewByRes = findViewById(R.id.tv_values_colors);
        textViewByRes.setTextColor(R.color.black);
        //设置文字背景颜色
//        textViewByRes.setBackgroundColor(Color.GREEN);
        //设置颜色来源资源文件
        textViewByRes.setBackgroundResource(R.color.red);





    }
}
